﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using RearLivestock.Common.Domains.hhx;
using RearLivestock.Common.Domains.hq;
using RearLivestock.Common.Dtos;
using RearLivestock.Common.Infrastructure.Interface;
using RearLivestock.RBAC.ErrorCodeEnum;

namespace RearLivestock.RBAC.Api.Application.hqApplication.Commands.Ablactationss
{
    public class FandAblactationsHnader : IRequestHandler<FandAblactationsCommand, Result>
    {
        private readonly IBaseRepository<Ablactations> AblactationsRepository;

        public FandAblactationsHnader(IBaseRepository<Ablactations> AblactationsRepository)
        {
            this.AblactationsRepository = AblactationsRepository;
        }
        public async Task<Result> Handle(FandAblactationsCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Deleted };
            try
            {
                var list = await (await AblactationsRepository.GetAll()).Where(d => d.AblactationId == request.AblactationId).FirstOrDefaultAsync();
                if (list != null)
                {
                    result.Data = list;
                    result.Code = (int)CommonErrorCode.Success;
                    result.Msg = "母猪断奶详情显示成功";
                }
            }
            catch (Exception)
            {
                result.Msg = "母猪断奶详情显示异常";
            }
            return result;
        }
    }
    
}
